﻿using System.Collections;

namespace LocalisationResourceManager
{
    /// <summary>
    /// Class for the collection of resource file paths.
    /// </summary>
    public class ResourcePath : Hashtable
    {
        public ResourcePath(string invariantString, string path, string name, string localizedValue, bool isNew)
        {
            var ng = new ResourceRow(invariantString, path, name, localizedValue, isNew);
            this[name] = ng;
        }

        public ResourceRow this[string invariantString, string path, string name]
        {
            get
            {
                if (!base.ContainsKey(name))
                {
                    ResourceRow entry = null;

                    if (base.Count > 0)
                    {
                        foreach (DictionaryEntry de in this)
                        {
                            entry = (ResourceRow)de.Value;
                            break;
                        }
                    }

                    // reuse translation if existing for another path.
                    this[name] = entry != null ? new ResourceRow(invariantString, path, name, entry.LocalizedValue, !Lrm.WriteUniqueResourceOnly) : new ResourceRow(invariantString, path, name, Lrm.ReplaceAltKey(invariantString), true);
                }

                return (ResourceRow)base[name];
            }
        }
    }
}
